<template>
    <div class="app-container contract-review-container">
        <div v-if="opt != 'add'">
            <el-descriptions title="">
                <el-descriptions-item label="序号">
                    <el-tag size="medium">{{ obj != null ? obj.index : index }}</el-tag>
                </el-descriptions-item>
            </el-descriptions>
        </div>
        <el-tabs v-model="activeName" @tab-click="handleClick">
            <el-tab-pane label="基本信息" name="first">
                <!-- 添加或修改【请填写功能名称】对话框 -->
                <el-form ref="form" :model="form" :rules="rules" label-width="80px">
                    <el-row v-if="showRelated">
                        <el-col :span="8" style="height: 55px;">
                            <el-form-item label="关联合同" prop="relatedContractName" label-width="110px">
                                <el-input v-model="form.relatedContractName" disabled="disabled" />
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="8" style="height: 55px;">
                            <el-form-item label="合同名称" prop="contractName" label-width="110px">
                                <el-input v-model="form.contractName" placeholder="请输入合同名称" :disabled="isView" />
                            </el-form-item>
                        </el-col>
                        <el-col :span="8" style="height: 55px;">
                            <el-form-item label="合同编号" prop="contractNumber" label-width="110px">
                                <el-input v-model="form.contractNumber" placeholder="请输入合同名称" :disabled="isView" />
                            </el-form-item>
                        </el-col>
                        <el-col :span="8" style="height: 55px;">
                            <el-form-item label="主分类" prop="classificationId" label-width="110px">
                                <treeselect v-model="form.classificationId" :options="optionData" placeholder="请选择主分类"
                                    :disabled="isView" />
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="8" style="height: 55px;">
                            <el-form-item label="合同金额" prop="contractAmount" label-width="110px">
                                <el-input v-model="form.contractAmount" placeholder="请输入合同金额" :disabled="isView" />
                            </el-form-item>
                        </el-col>
                        <el-col :span="8" style="height: 55px;">
                            <el-form-item label="签订时间" prop="signingTime" label-width="110px">
                                <el-date-picker clearable v-model="form.signingTime" type="date"
                                    value-format="yyyy-MM-dd" placeholder="请选择签订时间" style="width: 297px;"
                                    :disabled="isView">
                                </el-date-picker>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8" style="height: 55px;">
                            <el-form-item label="结束时间" prop="endTime" label-width="110px">
                                <el-date-picker clearable v-model="form.endTime" type="date" value-format="yyyy-MM-dd"
                                    placeholder="请选择结束时间" style="width: 297px;" :disabled="isView">
                                </el-date-picker>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="8" style="height: 55px;">
                            <el-form-item label="销售人员" prop="salespersonName" label-width="110px">
                                <el-input v-model="form.salespersonName" placeholder="请输入销售人员名称" @focus="userShow(1)"
                                    :disabled="isView" />
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item label="提供人" prop="provider" label-width="110px">
                                <el-input v-model="form.provider" placeholder="请输入提供人" :disabled="isView" />
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item label="提供来源" prop="provideSources" label-width="110px">
                                <el-input v-model="form.provideSources" placeholder="请输入提供来源" :disabled="isView" />
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="8">
                            <el-form-item label="业务费" prop="cost" label-width="110px">
                                <el-input v-model="form.cost" placeholder="请输入业务费" :disabled="isView" />
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item label="已收金额" prop="amountReceived" label-width="110px">
                                <el-input v-model="form.amountReceived" disabled="disabled" />
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row style="margin: 0px -120px 12px 40px;">
                        <el-row :gutter="10" class="mb8" v-if="isDel">
                            <el-col :span="1.5">
                                <span style="font-size: 14px;margin-left: 550px;">收款方式</span>&nbsp;&nbsp;&nbsp;&nbsp;
                            </el-col>
                        </el-row>
                        <el-table :data="tableData" style="width: 100%">
                            <el-table-column label="序号" type="index" align="center" prop="indexTwo" />
                            <el-table-column prop="paymentName" label="款项名称" min-width="120" align="center">
                                <template slot-scope="scope">
                                    <el-input v-model="scope.row.paymentName" :disabled="isView" />
                                </template>
                            </el-table-column>
                            <el-table-column prop="amountCollected" label="应收金额" min-width="60" align="center">

                                <template slot-scope="scope">
                                    <el-input v-model="scope.row.amountCollected" :disabled="isView" />
                                </template>
                            </el-table-column>
                            <el-table-column prop="estimatedCollectionTime" label="预计收款时间" min-width="80"
                                align="center">

                                <template slot-scope="scope">
                                    <el-date-picker clearable v-model="scope.row.estimatedCollectionTime" type="date"
                                        value-format="yyyy-MM-dd" :picker-options="{ disabledDate: dateOptions }"
                                        placeholder="请选择预计收款时间" :disabled="isView" >
                                    </el-date-picker>
                                </template>
                            </el-table-column>
                          <el-table-column
                            prop="remark"
                            label="备注"
                            min-width="60"
                            align="center"
                          >
                            <template slot-scope="scope">
                              <el-input
                                v-model="scope.row.remark"
                                :disabled="isView"
                                maxlength="6"
                              />
                            </template>
                          </el-table-column>
                          <el-table-column
                            prop="amountReceived"
                            label="已收金额"
                            min-width="40"
                            align="center"
                          />
                          <el-table-column
                            prop="unpaidAmount"
                            label="未收金额"
                            min-width="40"
                            align="center"
                          />
                            <el-table-column fixed="right" label="操作" min-width="40" align="center" v-if="isSave">

                                <template slot-scope="scope">
                                    <el-button type="text" size="small"
                                        @click="delContractInfo(scope.row)">删除</el-button>
                                </template>
                            </el-table-column>
                        </el-table>
                    </el-row>
                    <el-row>
                        <el-col :span="8" style="height: 55px;">
                            <el-form-item label="客户名称" prop="enterpriseName" label-width="110px">
                                <el-input v-model="form.enterpriseName" placeholder="请输入客户名称" :readonly="readonly"
                                    @focus="enterprise" :disabled="isView" />
                            </el-form-item>
                        </el-col>
                        <el-col :span="8" style="height: 55px;">
                            <el-form-item label="客户地址" prop="customerAddress" label-width="110px">
                                <el-input v-model="form.customerAddress" placeholder="请输入客户地址" disabled="disabled" />
                            </el-form-item>
                        </el-col>
                        <el-col :span="8" style="height: 55px;">
                            <el-form-item label="客户联系人" prop="customerContact" label-width="110px">
                                <el-input v-model="form.customerContact" placeholder="请输入客户联系人" disabled="disabled" />
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="8" style="height: 55px;">
                            <el-form-item label="联系电话" prop="telephone" label-width="110px">
                                <el-input v-model="form.telephone" placeholder="请输入联系电话" disabled="disabled" />
                            </el-form-item>
                        </el-col>
                        <el-col :span="8" style="height: 55px;">
                            <el-form-item label="创建人" prop="creationName" label-width="110px">
                                <el-input v-model="form.creationName" placeholder="请输入创建人" disabled="disabled" />
                            </el-form-item>
                        </el-col>
                        <el-col :span="8" style="height: 55px;">
                            <el-form-item label="创建时间" prop="creationTime" label-width="110px">
                                <el-date-picker clearable v-model="form.creationTime" type="date"
                                    value-format="yyyy-MM-dd" placeholder="请选择创建时间" style="width: 297px;"
                                    disabled="disabled">
                                </el-date-picker>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="24" style="height: 75px;">
                            <el-form-item label="附加条款" prop="additionalTerms" label-width="110px">
                                <el-input v-model="form.additionalTerms" type="textarea" placeholder="请输入附加条款内容"
                                    :autosize="{ minRows: 2, maxRows: 4 }" :disabled="isView" />
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="16" style="height: 55px;">
                            <el-form-item label="附件" label-width="110px">
                                <file-view :type="fileType" :businessId="businessId"
                                    :businessCode="contractCode"></file-view>
                            </el-form-item>
                        </el-col>
                    </el-row>
                </el-form>
                <div style="text-align: center;margin-top: 50px;">
                    <el-button @click="cancel">关 闭</el-button>
                </div>
            </el-tab-pane>
            <el-tab-pane label="产品2信息" name="second" :disabled="isSwitch">
                <div style="text-align: center;">
                    <el-row :gutter="10" class="mb8">
                        <el-col :span="1.5">
                            <el-button type="primary" @click="selectProduct" v-if="isSave">选择产品</el-button>
                        </el-col>
                    </el-row>
                    <el-row style="margin: 25px 0px 25px 0px;">产品列表</el-row>
                    <el-table v-loading="loading" :data="productInfoList" highlight-current-row style="width: 100%;">
                        <el-table-column label="产品类型" align="center" prop="productCategory">

                            <template slot-scope="scope">
                                <dict-tag :options="dict.type.product_type" :value="scope.row.productCategory" />
                            </template>
                        </el-table-column>
                        <el-table-column label="产品编号" align="center" prop="productNumber" />
                        <el-table-column label="产品名称" align="center" prop="productName" />
                        <el-table-column label="产品规格" align="center" prop="productSpecs" />
                        <el-table-column label="费用" align="center" prop="pricingRange" />
                        <el-table-column label="数量" align="center" prop="quantity" width="100" >
                            <template slot-scope="scope">
                                    <el-input
                                    v-model.number="scope.row.quantity"  
                                    placeholder="请输入"
                                    :disabled="isView"  
                                    maxlength="10"      
                                    step="0.01"         
                                    type="number"
                                    />
                                </template> 
                            </el-table-column>
                        <el-table-column label="合同交期" align="center" prop="contractDueDate"  >
                            <template slot-scope="scope">
                            <el-date-picker
                                clearable
                                v-model="scope.row.contractDueDate"  
                                type="date"                         
                                value-format="yyyy-MM-dd"           
                                placeholder="请选择"
                                width="115"           
                                :disabled="isView"                  
                                :picker-options="{
                                disabledDate: (time) => time.getTime() < Date.now() - 8.64e7
                                }"
                            />
                            </template>
                        </el-table-column>
                        <el-table-column label="备注" align="center" prop="remark" />
                      <!-- <el-table-column label="下单日期" align="center" prop="OrderDate" width="100" :show-overflow-tooltip="true">
                        <template slot-scope="scope">
                          <span>{{ parseTime(scope.row.OrderDate, '{y}-{m}-{d}') }}</span>
                        </template>
                      </el-table-column>
                      <el-table-column label="结案日期" align="center" prop="closeDate" width="100" :show-overflow-tooltip="true">
                        <template slot-scope="scope">
                          <span>{{ parseTime(scope.row.closeDate, '{y}-{m}-{d}') }}</span>
                        </template>
                      </el-table-column> -->
                      
                        <el-table-column label="操作" align="center" class-name="small-padding fixed-width" v-if="isSave">

                            <template slot-scope="scope">
                                <el-button size="mini" type="text" icon="el-icon-delete"
                                    @click="handleDeleteProduct(scope.row)">删除</el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                    <pagination v-show="total3 > 0" :total="total3" :page.sync="queryProductParams.pageNum"
                        :limit.sync="queryProductParams.pageSize" @pagination="getContractProductList" />
                    <div style="text-align: center;margin-top: 10px;">
                        <el-button @click="cancelProduct">关 闭</el-button>
                    </div>
                </div>
            </el-tab-pane>
            <el-tab-pane label="评审信息" name="third" :disabled="isReview">
                <div style="text-align: center;">
                    <div>
                        <el-form ref="formReview" :model="formReview" :inline="true" :rules="reviewRules"
                            v-if="reviewView">
                            <el-row style="line-height: 2px;">
                                <el-col :span="8" style="margin-left: 180px;">
                                    <el-form-item label="评审结果" prop="reviewResult" label-width="90px">

                                        <template>
                                            <el-radio-group v-model="formReview.reviewResult" :disabled="isOpt"
                                                @change="changeReviewComments">
                                                <el-radio :label="0">同意</el-radio>
                                                <el-radio :label="1">退回</el-radio>
                                                <el-radio :label="2">办结</el-radio>
                                                <el-radio :label="3">终止</el-radio>
                                            </el-radio-group>
                                        </template>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="7" style="height: 20px;width: 33%;">
                                    <el-form-item label="评审人" prop="reviewer" label-width="100px"
                                        v-if="formReview.reviewResult === 0">
                                        <el-input v-model="formReview.reviewer" placeholder="请选择评审人" readonly="readonly"
                                            style="width: 207px;" />
                                    </el-form-item>
                                    <el-input v-model="formReview.reviewerId" type="hidden" />
                                </el-col>
                                <el-col :span="1">
                                    <el-button style="margin-left: -20px;" type="primary" @click="selectReviewUser"
                                        v-if="isSelect && formReview.reviewResult === 0">选择</el-button>
                                </el-col>
                            </el-row>
                            <el-row>
                                <el-col>
                                    <el-form-item label="评审意见" prop="reviewComments" label-width="110px">
                                        <el-input v-model="formReview.reviewComments" type="textarea"
                                            placeholder="请输入内容" :rows="4" :disabled="isOpt"
                                            style="width: 657px;margin-right: 100px;" />
                                    </el-form-item>
                                </el-col>
                            </el-row>
                        </el-form>
                        <el-row>
                            <el-table v-loading="loading" :data="reviewList">
                                <el-table-column label="评审人" align="center" prop="reviewer" width="150" />
                                <el-table-column label="评审结果" align="center" prop="reviewResult" width="80">

                                    <template slot-scope="scope">
                                        <dict-tag :options="dict.type.contract_review_result"
                                            :value="scope.row.reviewResult" />
                                    </template>
                                </el-table-column>
                                <el-table-column label="评审意见" align="center" prop="reviewComments" />
                                <el-table-column label="评审时间" align="center" prop="reviewTime" width="100">

                                    <template slot-scope="scope">
                                        <span>{{ parseTime(scope.row.reviewTime, '{y}-{m}-{d}') }}</span>
                                    </template>
                                </el-table-column>
                            </el-table>
                        </el-row>
                        <div style="text-align: center;margin-top: 15px;">
                            <el-button type="primary" @click="submitReviewForm" v-if="isShowButton">保 存</el-button>
                            <el-button @click="cancel">关 闭</el-button>
                        </div>
                    </div>
                    <div>

                    </div>
                </div>
            </el-tab-pane>
        </el-tabs>
        <select-user ref="select" :type="userType" :sign="sign" @ok="selectUser"></select-user>
        <el-dialog :title="title" :visible.sync="open" width="1000px" append-to-body>
            <el-row>
                <el-col :span="5">
                    <MainType :typeCode="enterpriseCode" @getNode="getNodeEnterprise" :isTree="isTree"></MainType>
                </el-col>
                <el-col :span="19">
                    <el-form :model="queryEnterpriseParams" ref="queryFormEnterprise" size="small" :inline="true"
                        v-show="showSearch" label-width="100px">
                        <el-form-item label="企业名称" prop="enterpriseName">
                            <el-input v-model="queryEnterpriseParams.enterpriseName" placeholder="请输入企业名称" clearable
                                @keyup.enter.native="handleQueryEnterprise" />
                        </el-form-item>
                        <el-form-item>
                            <el-button type="primary" icon="el-icon-search" size="mini"
                                @click="handleQueryEnterprise">搜索</el-button>
                            <el-button icon="el-icon-refresh" size="mini" @click="resetQueryEnterprise">重置</el-button>
                            <el-button type="primary" size="mini" @click="saveSelectEnterprise">确定</el-button>
                        </el-form-item>
                    </el-form>
                    <el-table ref="tableEnterprise" v-loading="loading" style="width: 100%"
                        @selection-change="handleSelectionChangeEnterprise" :data="infoList" highlight-current-row>
                        <el-table-column type="selection" width="45" align="center" />
                        <el-table-column label="企业名称" align="center" prop="enterpriseName" />
                        <el-table-column label="联系人" align="center" prop="contacts" />
                        <el-table-column label="联系电话" align="center" prop="telephone" show-overflow-tooltip="true" />
                    </el-table>
                    <pagination v-show="total1 > 0" :total="total1" :page.sync="queryEnterpriseParams.pageNum"
                        :limit.sync="queryEnterpriseParams.pageSize" @pagination="getEnterpriseList" />
                </el-col>
            </el-row>
        </el-dialog>
        <el-dialog :title="titleProduct" :visible.sync="openProduct" width="1200px" append-to-body>
            <el-row>
                <el-col :span="5">
                    <MainType :typeCode="qualificationCode" @getNode="getNodeProduct" :isTree="isTree"></MainType>
                </el-col>
                <el-col :span="19">
                    <el-form :model="queryContractProductParams" ref="queryContractForm" size="small" :inline="true"
                        v-show="showSearch" label-width="68px">
                        <el-form-item label="产品类别" prop="productType">
                            <el-select v-model="queryContractProductParams.productType" placeholder="请选择产品类别" clearable>
                                <el-option v-for=" dict  in  dict.type.product_type " :key="dict.value"
                                    :label="dict.label" :value="dict.value" />
                            </el-select>
                        </el-form-item>
                        <el-form-item label="产品编号" prop="productNo">
                            <el-input v-model="queryContractProductParams.productNo" placeholder="请输入产品编号" clearable
                                @keyup.enter.native="handleQuery" />
                        </el-form-item>
                        <el-form-item label="产品名称" prop="productName">
                            <el-input v-model="queryContractProductParams.productName" placeholder="请输入产品名称" clearable
                                @keyup.enter.native="handleQuery" />
                        </el-form-item>
<!--                        <el-form-item label="产品状态" prop="productStatus">-->
<!--                            <el-select v-model="queryContractProductParams.productStatus" placeholder="请选择产品状态"-->
<!--                                clearable>-->
<!--                                <el-option v-for=" dict  in  dict.type.product_status " :key="dict.value"-->
<!--                                    :label="dict.label" :value="dict.value" />-->
<!--                            </el-select>-->
<!--                        </el-form-item>-->
                        <el-form-item>
                            <el-button type="primary" icon="el-icon-search" size="mini"
                                @click="handleQueryProduct">搜索</el-button>
                            <el-button icon="el-icon-refresh" size="mini" @click="resetQueryProduct">重置</el-button>
                            <el-button type="primary" size="mini" @click="saveContractProduct">确定</el-button>
                        </el-form-item>
                    </el-form>
                    <el-table v-loading="loading" :data="qualificationList" ref="tableProduct"
                        @selection-change="handleSelectionChangeContractProduct" row-key="id" highlight-current-row>
                        <el-table-column type="selection" width="45" align="center" />
                        <el-table-column label="序号" type="index" :index="indexMethod" />
                        <el-table-column label="产品类别" align="center" prop="productType">

                            <template slot-scope="scope">
                                <dict-tag :options="dict.type.product_type" :value="scope.row.productType" />
                            </template>
                        </el-table-column>
                        <el-table-column label="产品编号" align="center" prop="productNo" />
                        <el-table-column label="产品名称" align="center" prop="productName" />
                        <el-table-column label="定价范围" align="center" prop="productPrice" />
                    </el-table>
                    <pagination v-show="total2 > 0" :total="total2" :page.sync="queryContractProductParams.pageNum"
                        :limit.sync="queryContractProductParams.pageSize" @pagination="getProductList" />
                </el-col>
            </el-row>
        </el-dialog>
    </div>
</template>

<script>
import { listContractInfo, getContractInfo, delContractInfo, addContractInfo, updateContractInfo, saveContractPayment, updateContractPayment } from "@/api/contract/info";
import { listMethod, getMethod, delMethod, addMethod, updateMethod } from "@/api/contract/method";
import { listInfo, getInfo } from "@/api/enterprise/info";
import { listReviewInfo, getReviewInfo, delReviewInfo, addReviewInfo, updateReviewInfo, saveContractReview } from "@/api/contract/reviewInfo";
import { listQualification, getQualification, delQualification, addQualification, updateQualification, approveStatus } from "@/api/qualificationInfo/qualification";
import { listProductInfo, getProductInfo, delProductInfo, addProductInfo, updateProductInfo } from "@/api/contract/productInfo";
import { listReceivable, getReceivable } from "@/api/project/receivable";
import FileView from "@/components/FileView/index"
import SelectUser from "../system/role/selectUser.vue";
import { listType } from "@/api/maintype/type";
import Treeselect from "@riophae/vue-treeselect";
import MainType from "@/components/MainType/index"
import EnterpriseInfo from "../enterprise/info/index.vue";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
export default {
    name: "Information",
    dicts: ['business_classify', 'customer_industry', 'business_state', 'tracking_stage', 'enterprise_records', 'product_type', 'product_status', 'customer_industry', 'administrative_area', 'qualification_resume_status', 'contract_review_result'],
    components: { Treeselect, SelectUser, FileView, EnterpriseInfo, MainType },
    props: {
        opt: {
            type: String,
            default: ""
        },
        seas: {
            type: String,
            default: "0"
        },
        id: {
            type: String,
            default: ""
        },
        obj: {
            type: Object,
            default: null
        },
        //序号
        index: {
            type: Number,
            default: 0
        },
        uuid: {
            type: String,
            default: ""
        },
        isClick: {
            type: Boolean,
            default: ""
        },
        classId: {
            type: String,
            default: ""
        },
        business: {
            type: Object,
            default: null
        },
        cId: {
            type: String,
            default: ""
        },
        reContractId: {
            type: String,
            default: ""
        },
        reContractName: {
            type: String,
            default: ""
        }
    },
    data() {
        var reviewer = (rule, value, callback) => {
            if (!value) {
                return callback(new Error('评审人不能为空'));
            }
            return callback()
        };
        return {
            isSave: true,
            reviewView: true,
            isShowButton: true,
            isSelect: true,
            isOpt: false,
            showRelated: false,
            isView: false,
            readonly: true,
            disabled: false,
            openProduct: false,
            isDel: true,
            isTree: false,
            enterpriseCode: "enterprise",
            contractCode: 'contractInfo',
            qualificationCode: "qualification",
            titleProduct: "产品选择",
            readonly: true,
            isSwitch: true,
            isReview: true,
            isOpen: false,
            bId: "",
            refreshKey: 0,
            //选显卡默认选中
            activeName: 'first',
            activeNewName: 'one',
            userType: "1",
            sign: '1',
            // 遮罩层
            loading: true,
            // 选中数组
            eIds: [],
            eName: [],
            productIds: [],
            reviewList: [],
            productNames: [],
            productTypes: [],
            productCodes: [],
            productRanges: [],
            eCustomerAddress: [],
            eCustomerContact: [],
            eTelephone: [],
            productInfoList: [],
            qualificationList: [],
            // 非单个禁用
            single: true,
            // 非多个禁用
            multiple: true,
            // 显示搜索条件
            showSearch: true,
            // 总条数
            total: 0,
            total1: 0,
            total2: 0,
            total3: 0,
            // 【请填写功能名称】表格数据
            infoList: [],
            tableData: [],
            // 弹出层标题
            title: "",
            // 是否显示弹出层
            open: false,
            fileType: 0,
            // 表单参数
            queryContractForm: {},
            productForm: {},
            reviewerName: "",
            formReview: {
                reviewResult: 0,
                reviewComments: "同意"
            },
            form: {
                creationTime: this.showDate(),
                classificationId: this.classId == "" ? '650c44e1-b575-4b62-9d54-1ba9d1e8abb7' : this.classId,
                creationName: this.$store.state.user.name
            },
            // 表单校验
            rules: {},
            reviewRules: {
                reviewer: [
                    { required: true, validator: reviewer, trigger: "change" }
                ],
                reviewComments: [
                    { required: true, message: "评审意见不能为空", trigger: "blur" },
                    { max: 1000, message: '评审意见长度不能超过1000', trigger: 'blur' }
                ],
            },
            businessId: null,
            optionData: null,
            queryReceivableParams: {
                pageNum: 1,
                pageSize: 15,
                contractId: null,
                status: null,
            },
            queryReviewParams: {
                pageNum: 1,
                pageSize: 15,
                reviewId: null,
                contractId: null,
                reviewerId: null,
                reviewer: null,
                reviewComments: null,
                reviewTime: null,
                reviewResult: null
            },
            queryContractProductParams: {
                pageNum: 1,
                pageSize: 15,
                productType: null,
                productNo: null,
                productName: null,
                productStatus: null,
                classificationId: null
            },
            queryProductParams: {
                pageNum: 1,
                pageSize: 15,
                contractId: null,
                productId: null,
                productCategory: null,
                productNumber: null,
                productName: null,
                pricingRange: null
            },
            queryPaymentParams: {
                pageNum: 1,
                pageSize: 15,
                paymentId: null,
                contractId: null,
                paymentName: null,
                amountCollected: null
            },
            queryEnterpriseParams: {
                pageNum: 1,
                pageSize: 15,
                enterpriseName: null,
                enterpriseSource: null,
                enterpriseAbbreviation: null,
                administrativeArea: null,
                legalRepresentative: null,
                establishmentDate: null,
                contractAmount: null,
                enterpriseLabel: null,
                registeredCapital: null,
                industry: null,
                contacts: null,
                telephone: null,
                bankName: null,
                taxId: null,
                developmentId: null,
                transactionId: null,
                developmentManager: null,
                businessManager: null,
                enterpriseAddress: null,
                businessScope: null,
                enterpriseNature: null,
                markAs: '1',
                belongTo: null,
                creationTime: null,
                operateTime: null,
                operateId: null,
                departmentId: null,
                departmentName: null,
                organizationId: null,
                organizationName: null,
                classificationId: null
            },
        };
    },
    created() {
        this.listType();
        this.getContractProductList();
        this.getProductList();
        this.getEnterpriseList();
        this.getReviewList();
        if (this.opt == "view") {
            this.businessId = this.id;
            this.fileType = 2;
            this.isView = true;
            this.isReview = false;
            this.isSave = false;
            this.bId = this.id;
            this.reviewView = false;
            this.isShowButton = false;
            this.isSwitch = false;
            this.handleUpdate(this.id);
        }
        if (this.opt == "review") {
            this.businessId = this.id;
            this.fileType = 2;
            this.isView = true;
            this.isReview = false;
            this.isSave = false;
            this.bId = this.id;
            this.isSwitch = false;
            this.handleUpdate(this.id);
        }
    },
    methods: {
        changeReviewComments() {
            if (this.formReview.reviewResult == '0') {
                this.formReview.reviewComments = "同意";
            } else {
                this.formReview.reviewComments = "";
            }
        },
        submitReviewForm() {
            this.$refs["formReview"].validate(valid => {
                if (valid) {
                    const reviewInfo = {
                        reviewId: this.guid(),
                        contractId: this.cId,
                        reviewResult: this.formReview.reviewResult,
                        reviewComments: this.formReview.reviewComments,
                        reviewerId: this.formReview.reviewerId,
                        reviewer: this.formReview.reviewer
                    }
                    saveContractReview(reviewInfo).then(response => {
                        this.$modal.msgSuccess("新增成功");
                        this.open = false;
                        this.isOpt = true;
                        this.isShowButton = false;
                        this.isSelect = false;
                        this.getReviewList();
                    });
                }
            });
        },
        selectReviewUser() {
            this.userShow(2);
        },
        getReviewList() {
            this.loading = true;
            this.queryReviewParams.contractId = this.cId;
            listReviewInfo(this.queryReviewParams).then(response => {
                this.reviewList = response.rows;
                this.loading = false;
            });
        },
        saveContractProduct() {
            const productInfo = {
                contractId: this.cId,
                productId: this.productIds.toString(),
                productCategory: this.productTypes.toString(),
                productNumber: this.productCodes.toString(),
                productName: this.productNames.toString(),
                pricingRange: this.productRanges.toString()
            }
            addProductInfo(productInfo).then(response => {
                this.$modal.msgSuccess("新增成功");
                this.openProduct = false;
                this.isReview = false;
                this.getContractProductList();
            });
        },
        resetQueryProduct() {
            this.queryContractProductParams.classificationId = null
            this.queryContractProductParams.productStatus = null
            this.resetProduct();
            this.handleQueryProduct();
        },
        handleQueryProduct() {
            this.queryContractProductParams.pageNum = 1;
            this.getProductList();
        },
        handleSelectionChangeContractProduct(selection) {
            this.productIds = selection.map(item => item.id)
            this.productNames = selection.map(item => item.productName)
            this.productCodes = selection.map(item => item.productNo)
            this.productTypes = selection.map(item => item.productType)
            this.productRanges = selection.map(item => item.productPrice)
            this.single = selection.length !== 1
            this.multiple = !selection.length
        },
        getProductList() {
            this.loading = true;
            listQualification(this.queryContractProductParams).then(response => {
                this.qualificationList = response.rows;
                var numbers = this.productInfoList;
                setTimeout(() => {
                    this.carCheck(numbers);
                }, 200);
                this.total2 = response.total;
                this.loading = false;
            });
        },
        getNodeProduct(data, node, obj) {
            this.queryContractProductParams.classificationId = data.id
            this.getProductList()
        },
        cancelProduct() {
            this.$emit('change');
        },
        getContractProductList() {
            this.loading = true;
            this.queryProductParams.contractId = this.cId;
            listProductInfo(this.queryProductParams).then(response => {
                this.productInfoList = response.rows;
                if (this.productInfoList.length != 0) {
                    this.isReview = false;
                }
                this.total3 = response.total;
                this.loading = false;
            });
        },
        delContractInfo(row) {
            this.tableData = this.tableData.filter(data => data.paymentId !== row.paymentId)
        },
        guid() {
            function S4() {
                return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
            }
            return (S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4() + S4() + S4());
        },
        /** 搜索按钮操作 */
        handleQueryEnterprise() {
            this.queryEnterpriseParams.pageNum = 1;
            this.getEnterpriseList();
        },
        /** 重置按钮操作 */
        resetQueryEnterprise() {
            this.resetForm("queryFormEnterprise");
            this.handleQueryEnterprise();
        },

        getEnterpriseList() {
            this.loading = true;
            listInfo(this.queryEnterpriseParams).then(response => {
                this.infoList = response.rows;
                this.total1 = response.total;
                this.loading = false;
            });
        },
        getFile(data) {
            console.log(JSON.stringify(data))
        },
        indexMethod(index) {
            return (this.queryContractProductParams.pageNum - 1) * this.queryContractProductParams.pageSize + index + 1;
        },
        listType() {
            listType({ typeCode: 'contractInfo' }).then(res => {
                this.optionData = res.data;
            })
        },
        beforeHandle() {
            if (3 == "no") {
                this.$message.error("请先保存商机基本信息！");
            } else {

            }
        },
        handleClick(tab, event) {
            if (tab.name == 'first') {

            }
            if (tab.name == 'second') {

            }
            if (tab.name == 'third') {

            }
        },
        handleNewClick(tab, event) {
            if (tab.name == 'one') {
                this.$refs.tableSeas.clearSelection(); // 清空所有选择
            }
            if (tab.name == 'two') {
                this.$refs.tableEnterprise.clearSelection(); // 清空所有选择
            }
        },
        userShow(type) {
            this.show = type
            this.$refs.select.show();

        },
        handleDeleteProduct(row) {
            const ids = row.id || this.ids;
            this.$modal.confirm('是否确认删除产品名称为"' + row.productName + '"的数据信息？').then(function () {
                return delProductInfo(ids);
            }).then(() => {
                this.getContractProductList();
                this.$modal.msgSuccess("删除成功");
            }).catch(() => { });
        },
        // 取消按钮
        cancel() {
            this.$emit('change');
        },
        // 表单重置
        resetProduct() {
            this.form = {
                id: null,
                productType: null,
                productNo: null,
                productName: null,
                productPrice: null,
                productSellPrice: null,
                productStatus: null,
                enterpriseId: null,
                enters: null,
                productRemark: null,
                exeStandard: null,
                template: null,
                operateId: null,
                departmentId: null,
                organizationId: null,
                departmentName: null,
                organizationName: null,
                creationTime: null,
                operateTime: null,
                createId: null,
                selectUrl: null,
                userName: null,
                releaseTime: null,
                approve: null,
                classificationId: null,
                uploadFile: null,
            }
            this.resetForm("queryContractForm");
        },
        reset() {
            this.form = {
                contractId: null,
                classificationId: null,
                contractName: null,
                relatedContractId: null,
                relatedContractName: null,
                contractAmount: null,
                signingTime: null,
                endTime: null,
                enterpriseId: null,
                enterpriseName: null,
                customerAddress: null,
                customerContact: null,
                telephone: null,
                salespersonId: null,
                salespersonName: null,
                additionalTerms: null,
                belongTo: null,
                creationId: null,
                creationName: null,
                creationTime: null,
                operateTime: null,
                operateId: null,
                departmentId: null,
                departmentName: null,
                organizationId: null,
                organizationName: null,
                delFlag: null,
                amountReceived: null,
                state: null
            };
            this.resetForm("form");
        },
        /** 修改按钮操作 */
        handleUpdate(id) {
            this.reset();
            getContractInfo(id).then(response => {
                this.form = response.data;
                if (this.form.relatedContractName != "" && this.form.relatedContractName != null) {
                    this.showRelated = true;
                }
                this.form.creationTime = this.formatterDate(this.form.creationTime)
            });
            this.queryPaymentParams.contractId = id;
            listMethod(this.queryPaymentParams).then(response => {
                this.tableData = response.rows;
            });
            this.queryReceivableParams.contractId = id;
            this.queryReceivableParams.status = '1';
            listReceivable(this.queryReceivableParams).then(response => {
                var listTable = response.rows;
                var sum = 0;
                for (var a = 0; a < listTable.length; a++) {
                    sum = sum + parseInt(listTable[a].paidInAmount)
                }
                console.log(sum)
                this.form.amountReceived = sum;
            });
        },
        dateOptions(time) {
            return time.getTime() < Date.now() - 24 * 60 * 60 * 1000
        },
        showDate() {
            var mydate = new Date();
            var str = "" + mydate.getFullYear() + "-";
            str += (mydate.getMonth() + 1) <= 9 ? "0" + (mydate.getMonth() + 1) + "-" : mydate.getMonth() + 1 + "-";
            str += mydate.getDate() <= 9 ? "0" + mydate.getDate() : mydate.getDate();
            return str;
        },
        formatterDate(date) {
            var mydate = new Date(date);
            var str = "" + mydate.getFullYear() + "-";
            str += (mydate.getMonth() + 1) <= 9 ? "0" + (mydate.getMonth() + 1) + "-" : mydate.getMonth() + 1 + "-";
            str += mydate.getDate() <= 9 ? "0" + mydate.getDate() : mydate.getDate();
            return str;
        },
        close() {
            this.open = false;
        },
        enterprise() {
            this.open = true;
        },
        selectUser(userId, userName, phone, position) {
            if (this.show == '1') {
                this.$set(this.form, 'salespersonName', userName)
                this.$set(this.form, 'salespersonId', userId)
            }
            if (this.show == '2') {
                this.$set(this.formReview, 'reviewer', userName)
                this.$set(this.formReview, 'reviewerId', userId)
            }
        },
        handleSelectionChangeEnterprise(selection) {
            if (selection.length > 1) {
                this.$refs.tableEnterprise.clearSelection(); // 清空所有选择
                this.$refs.tableEnterprise.toggleRowSelection(selection.pop()); // 设置选择项
            } else {
                this.eIds = selection.map(item => item.enterpriseId)
                this.eName = selection.map(item => item.enterpriseName)
                this.eCustomerAddress = selection.map(item => item.enterpriseAddress)
                this.eCustomerContact = selection.map(item => item.contacts)
                this.eTelephone = selection.map(item => item.telephone)
                this.single = selection.length !== 1
                this.multiple = !selection.length
            }
        },
        getNodeEnterprise(data, node, obj) {
            this.queryEnterpriseParams.classificationId = data.id
            this.getEnterpriseList()
        },
        saveSelectEnterprise() {
            this.$set(this.form, 'enterpriseName', this.eName.toString())
            this.$set(this.form, 'enterpriseId', this.eIds.toString())
            this.$set(this.form, 'customerAddress', this.eCustomerAddress.toString())
            this.$set(this.form, 'customerContact', this.eCustomerContact.toString())
            this.$set(this.form, 'telephone', this.eTelephone.toString())
            this.close()
        },
    }
};
</script>

<style scoped lang="scss">
.contract-review-container {
  overflow-y: auto;
  overflow-x: auto;
  padding: 16px;
  max-width: 100%;
  max-height: 85vh;
  box-sizing: border-box;
}

::v-deep .el-table .el-table__header-wrapper .el-checkbox {
    display: none;
}

::v-deep .el-dialog__header {
    padding-top: 5px;
}

::v-deep .el-tab-pane {
    overflow-x: auto;
}
</style>
